home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 300_01 / bolt.c < prev    next >
C/C++ Source or Header  |  1989-12-28  |  2KB  |  58 lines

  1. /*   HEADER:   CUG300;
  2.       TITLE:   Bolt stress demonstration program;
  3.        DATE:   4/20/1989;
  4. DESCRIPTION:   "Calculates the stress in a series of bolts";
  5.     VERSION:   1.0;
  6.    FILENAME:   BOLT.C;
  7.    SEE-ALSO:   MAT_V2D.H;
  8. */
  9.  
  10.    #include  "mat_v2d.h"
  11.    #include  <math.h>
  12.    #include  <stdio.h>
  13.  
  14.    main()
  15.    {
  16.     unsigned rows,cols,toksz,i;
  17.    enum     {ID_,LOAD,DIAM,THRDS};
  18.    enum     {ID,AREA,STRESS,OUTFLDS};
  19.    FILE     *FN;
  20.    struct   tmat *inp,*out;
  21.    float    Net_Area,Stress;
  22.  
  23. /*-- Scan and input the data from a textfile (BOLT.INP) --------------*/
  24.  
  25.       mtcnt("BOLT.INP",&rows,&cols,&toksz);
  26.       tdim(inp,rows,cols,toksz);         /*   Note that array size is */
  27.       tdim(out,rows,OUTFLDS,toksz+10);   /*   based on textfile       */
  28.       mtget("BOLT.INP",inp);             /*   contents                */
  29.  
  30. /*-- Compute desired parameters --------------------------------------*/
  31.  
  32.       rows(inp,i) {
  33.  
  34. /*    Note: Casts of enum index references to integer may be required for
  35.       some compilers
  36. */
  37.          Net_Area = 0.7854 * pow(tf(inp,i,DIAM,4),2) -     0.9743/
  38.                                                      /*---------------*/
  39.                                                       tf(inp,i,THRDS,4);
  40.          Stress   =     tf(inp,i,LOAD,4)/
  41.                        /*------------*/
  42.                            Net_Area;
  43.  
  44.          strcpy( t(out,i,ID), t(inp,i,ID_)); /*  Transfer results to  */ 
  45.          ft( out,i,AREA, Net_Area,30,3,4);   /*  the output dynamic   */
  46.          ft( out,i,STRESS, Stress,30,3,4);   /*  text array           */
  47.       }
  48.  
  49. /*-- Output the results array with appropriate column headings -------*/
  50.  
  51.       flcreat("BOLT.OUT",FN);
  52.       mtput(FN, out, " Sample Area(sq_in) Stress(lbs/sq_in)",
  53.                      " Sample Area(sq_in) Stress(lbs/sq_in)", 72, 3);
  54.       fclose(FN);
  55.    }
  56.  
  57.  
  58.